/*
 * Lab08A1.cpp
 * Example comparing pointers
 *
 *  Created on: Apr 10, 2014
 *      Author: Anthony Varghese
 */

#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::ostream;

class Data{
public:
	Data()     : data(0), name("Data")		{	cout << "Default constructor: " << *this;	}
	Data(double d): data(d), name("Data")	{	cout << "Alternate constructor: " << *this;	}
	Data(string n): data(0), name(n)		{	cout << "Alternate constructor: " << *this;	}
    ~Data()									{ 	cout << "Destructor for Data: " << *this;    }
    Data(const Data& o): data(o.data), name(o.name){	cout << "Copy constructor: " << *this; }
    Data& operator =(const Data& rhs)		{ 	cout << "Assignment operator: " << *this << endl;  	return *this; }
    friend ostream& operator<<(ostream& os, const Data& d);
private:
    double data;
    string name;
};

ostream& operator<<(ostream& os, const Data& d){
	os << "  Data: " << d.data << " " << d.name << endl;	return os;
}

#include <memory>  // for auto_ptr

int main(){
    cout << "CSIS 237 Lab 8 - Basic Pointer example" << endl;

    int* p = new int;
    *p = 200;
    cout << " p is pointing to " << *p << endl;

    /* Step 2 - uncomment this part *
    const int SIZE = 100;
    int* q = new int[SIZE];
    for (int i=0; i<SIZE; i++)
    	q[i] = SIZE - i;
    cout << "Array q has: ";
    for (int i=0; i<SIZE; i++)
    	cout << "  " << q[i];
    cout << endl;
    */

    /* Step 3 - uncomment this part *
    Data d("d");
    Data* dheap = new Data("dheap");
    std::auto_ptr<Data> dsmart( new Data("dsmart") );

    cout << endl;
    cout << "    d object:      " << d;
    cout << "    dheap object:  " << *dheap;
    cout << "    dsmart object: " << *dsmart;
    cout << endl;

    delete dheap;
    */
    cout << "... done" << endl;
}
